<template>
  <div>
    <Head/>
    <left/>
    <div style="position: absolute;top: 60px;left: 200px">
      {{ id }}
      {{ task }}
      <div v-for="i in params['params']" :key="i.name">
        <p v-if="i.type=='select'">{{ i.name }}
          <select name="" id="" v-model="form['params']['请假类型']">
            <option :value="j.name" v-for="j in i['value']" :key="j.id">{{ j.name }}</option>
          </select>
        </p>
        <p v-else-if="i.type=='text'">
          {{ i.name }}<input type="text" v-model="form['params']['请假人']">
        </p>
        <p v-else-if="i.type=='date1'">{{ i.name }}<input type="date" v-model="form['params']['开始时间']"></p>
        <p v-else-if="i.type=='date2'">{{ i.name }}<input type="date" v-model="form['params']['结束时间']"></p>
        <p v-else-if="i.type=='radio'">{{ i.name }}<input type="radio" v-model="form[i.name]"></p>
        <p v-else-if="i.type=='checkbox'">{{ i.name }}<input type="checkbox" v-model="form[i.name]"></p>

      </div>
      审批人
      <van-checkbox-group v-model="form['roleid']" direction="horizontal">
        <van-checkbox :name="i.id" v-for="i in users" :key="i.id">{{ i.name }}</van-checkbox>
      </van-checkbox-group>
      <van-button @click="add">修改</van-button>
    </div>
  </div>
</template>

<script>
import head from "@/components/head";
import left from "@/components/left";
import axios from 'axios'
import maxios from "@/http/axios";

export default {
  components: {
    'Head': head,
    'left': left
  },
  name: "holiday",
  data() {
    return {
      userid: localStorage.getItem('userid'),
      id: this.$route.query.id,
      task: {},
      params: {},
      form: {},
      users: []

    }
  },
  methods: {
    getholiday() {
      axios({'url': '/work/puttask?id=' + this.id, 'method': 'get'}).then(res => {
        if (res.data.code == 200) {
          this.form = res.data.list

          this.getyu()
        }
      })
    },
    getyu() {
      maxios('/work/holiday?id=' + this.form['yewuid'], 'get').then(res => {
        // this.holiday = res.list
        console.log(res.list)
        this.params = res.list
        this.form.title = res.list['name'] + this.form['params']['请假人']
        console.log(this.holiday)
        console.log(this.form.title)
      })
    },
    get_users() {
      maxios('/users/user', 'get')
          .then(res => {
            if (res.code == 200) {
              this.users = res.list
            }
          })
    },
    add() {
      let data = new FormData()
      data = JSON.stringify(this.form['params'])
      this.form['params'] = data
      axios({'url': '/work/puttask', 'method': 'put', data: this.form}).then(res => {
        if (res.data.code == 200) {
          alert('修改成功')
        }
      })


    }
  },
  mounted() {
    this.getholiday()
    this.get_users()
  }


}
</script>

<style scoped>

</style>